#Programmer: Nathan Estell #Description: Uses the principle that light minimizes trip length to show that angle1=angle2 in the case of reflection and that n1*sin(angle1)=n2*sin(angle2). It runs through a given number #of iterations to find the shortest time, then calculates angles from the shortest path. $CalculateReflectionAngle_Click = { <# if ($HDistSD.Text -eq "0") { $ReflectionAngle1 = [Math]::Atan(($VDistSD.Text/2)/$HDistSM.Text) * 180/[Math]::PI $labelIncidenceAngle.Text = "Incidence Angle: $ReflectionAngle1 deg" $labelReflectionAngle.Text = "Reflection Angle: $ReflectionAngle1 deg" } if ($HDistSD.Text -ne "0") { $labelIncidenceAngle.Text = "Incidence Angle:" $labelReflectionAngle.Text = "Reflection Angle:" } #> $iterations=$Iterations1.Text [double]$increment = $VDistSD.Text/$iterations $progressbar2.Value = 0 $progressbar2.Maximum=$iterations for ($i = 0; $i -lt $iterations; $i++) { $VPosition = $increment * $i $distance1 = [Math]::Sqrt([math]::Pow($VPosition,2)+[math]::Pow($HDistSM.Text,2)) $distance2 = [Math]::Sqrt([Math]::Pow(($VDistSD.Text - $VPosition), 2) + [Math]::Pow(($HDistSM.Text - $HDistSD.Text), 2)) $distanceTotal = $distance1 + $distance2 if ($i -eq 0) { $VPositionLowest = $VPosition $lowestDistance=$distanceTotal } if ($distanceTotal -lt $lowestDistance) { $VPositionLowest = $VPosition $lowestDistance = $distanceTotal } $IncidenceAngle = [Math]::Atan($VPosition/$HDistSM.Text) * 180/[Math]::PI $ReflectionAngle2 = [Math]::Atan(($VDistSD.Text - $VPosition)/($HDistSM.Text - $HDistSD.Text)) * 180/[Math]::PI $labelIncidenceAngle2.Text = "Incidence Angle: $IncidenceAngle deg" $labelReflectionAngle2.Text = "Reflection Angle: $ReflectionAngle2 deg" $progressbar2.Increment(1) [System.Windows.Forms.Application]::DoEvents() } $IncidenceAngle = [Math]::Atan($VPositionLowest/$HDistSM.Text) * 180/[Math]::PI $ReflectionAngle2 = [Math]::Atan(($VDistSD.Text - $VPositionLowest)/($HDistSM.Text - $HDistSD.Text)) * 180/[Math]::PI $labelIncidenceAngle2.Text = "Incidence Angle: $IncidenceAngle deg" $labelReflectionAngle2.Text="Reflection Angle: $ReflectionAngle2 deg" } $buttonCalculateAngles_Click = { <# $angle2R= [Math]::Asin($M1RI.Text/$M2RI.Text*[Math]::Sin([double]$A1.Text*[Math]::PI/180))*180/([Math]::PI) $labelAngle2R.Text = "Angle 2: $angle2R deg" #> $Iterations2 = [Math]::Sqrt($Iterations3.Text) [double]$increment = $VDSD.Text/$Iterations2 $progressbar1.Value=0 $progressbar1.Maximum=$Iterations3.Text for ($i = 0; $i -lt $Iterations2; $i++) { $VPosition1 = $increment * $i $distance1 = [Math]::Sqrt([math]::Pow($VPosition1 - $VDSD.Text, 2) + [math]::Pow(($HDSD.Text - $M2W.Text)/2, 2)) for ($i1 = 0; $i1 -lt $Iterations2; $i1++) { $VPosition2 = $increment * $i1 $distance2 = [Math]::Sqrt([Math]::Pow($VPosition1 - $VPosition2, 2) + [Math]::Pow($M2W.Text, 2)) $distance3 = [Math]::Sqrt([math]::Pow($VPosition2, 2) + [math]::Pow(($HDSD.Text - $M2W.Text)/2, 2)) $TimeTotal = [double]$M1RI.Text * $distance1 + [double]$M2RI.Text * $distance2 + [double]$M1RI.Text * $distance3 if ($i -eq 0) { $VPosition1Lowest = $VPosition1 $VPosition2Lowest = $VPosition2 $lowestTime = $TimeTotal } if ($TimeTotal -lt $lowestTime) { $VPosition1Lowest = $VPosition1 $VPosition2Lowest = $VPosition2 $lowestTime = $TimeTotal } $Angle1LTM = [Math]::Abs([Math]::Atan(($VDSD.Text - $VPosition1)/(($HDSD.Text - $M2W.Text)/2))) $Angle2LTM = [Math]::Abs([Math]::Atan(($VPosition2 - $VPosition1)/$M2W.Text)) $Angle3LTM = $Angle2LTM $Angle4LTM = [Math]::Abs([Math]::Atan($VPosition2/(($HDSD.Text - $M2W.Text)/2))) $A1.Text = $Angle1LTM * 180/[Math]::PI $A2.Text = $Angle2LTM * 180/[Math]::PI $A3.Text = $Angle3LTM * 180/[Math]::PI $A4.Text = $Angle4LTM * 180/[Math]::PI $N1SA1.Text = [double]$M1RI.Text * [Math]::Sin($Angle1LTM) $N2SA2.Text = [double]$M2RI.Text * [Math]::Sin($Angle2LTM) $N2SA3.Text = [double]$M2RI.Text * [Math]::Sin($Angle3LTM) $N1SA4.Text = [double]$M1RI.Text * [Math]::Sin($Angle4LTM) $progressbar1.Increment(1) [System.Windows.Forms.Application]::DoEvents() } } $Angle1LTM = [Math]::Abs([Math]::Atan(($VDSD.Text-$VPosition1Lowest)/(($HDSD.Text - $M2W.Text)/2))) $Angle2LTM = [Math]::Abs([Math]::Atan(($VPosition2Lowest-$VPosition1Lowest)/$M2W.Text)) $Angle3LTM = $Angle2LTM $Angle4LTM = [Math]::Abs([Math]::Atan($VPosition2Lowest/(($HDSD.Text - $M2W.Text)/2))) $A1.Text = $Angle1LTM * 180/[Math]::PI $A2.Text = $Angle2LTM * 180/[Math]::PI $A3.Text = $Angle3LTM * 180/[Math]::PI $A4.Text = $Angle4LTM * 180/[Math]::PI $N1SA1.Text = [double]$M1RI.Text * [Math]::Sin($Angle1LTM) $N2SA2.Text = [double]$M2RI.Text * [Math]::Sin($Angle2LTM) $N2SA3.Text = [double]$M2RI.Text * [Math]::Sin($Angle3LTM) $N1SA4.Text = [double]$M1RI.Text * [Math]::Sin($Angle4LTM) }